package org.elzat.healthboxgatewayapp.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultEntity<T> {
    private String msg;
    private int code;
    private T data;

    public static final int OK = 200;
    public static final int FAILURE = 400;
    public static final int UNAUTHORIZED = 401;
    public static final int FORBIDDEN = 403;

    public static ResultEntityBuilder ok() {
        return new ResultEntityBuilder().code(OK);
    }
    public static ResultEntityBuilder failure() {
        return new ResultEntityBuilder().code(FAILURE);
    }
    public static ResultEntityBuilder unauthorized() {
        return new ResultEntityBuilder().code(UNAUTHORIZED);
    }
    public static ResultEntityBuilder forbidden() {
        return new ResultEntityBuilder().code(FORBIDDEN);
    }
    public static class ResultEntityBuilder {
        private String msg;
        private int code;
        private Object data;
        public ResultEntityBuilder code(int code) {
            this.code = code;
            return this;
        }
        public ResultEntityBuilder msg(String msg) {
            this.msg = msg;
            return this;
        }
        public <T> ResultEntity<T> data(T data) {
            return new ResultEntity<>(msg, code, data);
        }
        public <T> ResultEntity<T> build() {
            return new ResultEntity<>(msg, code, null);
        }
    }
}
